package com.dody.agile.payment.transaction;


import com.dody.agile.payment.classification.PaymentClassification;
import com.dody.agile.payment.database.PayrollDatabase;
import com.dody.agile.payment.database.PayrollDatabaseFactory;
import com.dody.agile.payment.employee.Employee;
import com.dody.agile.payment.method.HoldMethod;
import com.dody.agile.payment.method.PaymentMethod;
import com.dody.agile.payment.schedule.PaymentSchedule;

/**
 * @author ShiXin
 * @date 2019/4/9 20:31
 * @description ExamStack
 */
public abstract class AddEmployeeTransaction implements Transaction {

    private Integer empId;
    private String itsAddress;
    private String itsName;
    PayrollDatabase payrollDatabase = PayrollDatabaseFactory.getInstance();

    public AddEmployeeTransaction() {
    }

    public AddEmployeeTransaction(Integer empId, String itsAddress, String itsName) {
        this.empId = empId;
        this.itsAddress = itsAddress;
        this.itsName = itsName;
    }

    abstract PaymentClassification getClassification();

    abstract PaymentSchedule getSchedule();

    @Override
    public void execute() {
        PaymentClassification pc = getClassification();
        PaymentSchedule ps = getSchedule();
        PaymentMethod pm = new HoldMethod();
        Employee e = new Employee(this.empId, this.itsAddress, this.itsName);
        e.setClassification(pc);
        e.setMethod(pm);
        e.setSchedule(ps);
        payrollDatabase.addEmployee(this.empId,e);
    }
}
